<template>
  <div class="bottom-menu">
    <check-button
      class="select-all"
      :ischecked="selectAll"
      @click.native="selectAllClick"
    ></check-button>
    <span>全选</span>
    <span class="total-price">合计：¥{{ priceAll }}</span>
    <span class="buy-product">去结算{{ checkLen }}</span>
  </div>
</template>
<script>
import CheckButton from "./CheckButton.vue";
import { mapGetters } from "vuex";
export default {
  name: "cartbottom",
  components: {
    CheckButton,
  },
  computed: {
    ...mapGetters(["getCartList", "getCartListLen"]),
    selectAll() {
      if (!this.getCartListLen) return false;
      return !this.getCartList.find((item) => !item.checked);
    },
    priceAll() {
      return this.getCartList
        .filter((item) => {
          return item.checked;
        })
        .reduce((old, item) => {
          return old + item.count * item.price;
        }, 0)
        .toFixed(2);
    },
    checkLen() {
      return this.getCartList.filter((item) => item.checked).length;
    },
  },
  methods: {
    selectAllClick() {
      if (this.selectAll) {
        this.getCartList.forEach((el) => (el.checked = false));
      } else {
        this.getCartList.forEach((el) => (el.checked = true));
      }
    },
  },
};
</script>
<style scoped>
.bottom-menu {
  width: 100%;
  background-color: #eee;
  position: fixed;
  bottom: 49px;
  left: 0;
  box-shadow: 0 -2px 3px rgba(0, 0, 0, 0.2);
  font-size: 14px;
  color: #888;
  line-height: 44px;
  padding-left: 35px;
  box-sizing: border-box;
}

.bottom-menu .select-all {
  position: absolute;
  line-height: 0;
  left: 12px;
  top: 13px;
}

.bottom-menu .total-price {
  margin-left: 15px;
  font-size: 16px;
  color: #666;
}

.bottom-menu .buy-product {
  background-color: orangered;
  color: #fff;
  width: 100px;
  height: 44px;
  text-align: center;
  line-height: 44px;
  float: right;
}
</style>
